--[[
Copyright:www.vxinyou.com
Author:xuerui
CreateTime:2013-06-18
Description:PageView
--]]

local clsPageView = Class("lua/cc/clsNode.lua"):Inherit()

function clsPageView:create(config)
	local c = clone(config)
	self._root = PageView:create()	
	self._root:setPosition(ccp(c.x,c.y))
	self._root:setTouchEnabled(true)					
	self.x = c.x
	self.y = c.y	
	self.sx = c.sx
	self.sy = c.sy
	self.bg = c.bg
end

function clsPageView:scrollToPage(idx)
	self._root:scrollToPage( idx-1 )
end

function clsPageView:getCurPageIndex()
	return self._root:getCurPageIndex() + 1
end


function clsPageView:insertCellAtIndex(idx)
	self._root:insertCellAtIndex(idx)
end

function clsPageView:getContentSize()
	return self._root:getContentSize()
end

function clsPageView:setPosition(x,y)
	local size = self:getContentSize()		
	self._root:setPosition(ccp( x-size.width/2,y-size.height/2 ))
end

function clsPageView:setAnchorPoint(ax,ay)
	self.ax = ax
	self.ay = ay	
end

function clsPageView:setContentSize(width, height)
	self._root:setContentSize(CCSizeMake(width,height))	
	local x,y = self:getPosition()
	self:setPosition(x,y)
end

function clsPageView:removeFromParentAndCleanup()
	self._root:removeFromParentAndCleanup(true)
end

function clsPageView:addPage(data)
	local l = Layout:create()	
	l:setContentSize(CCSizeMake(self.sx, self.sy))
	l:setPosition(ccp(self.x,self.y))
	local imgBg = self.bg or "scrollviewbg.png"
	local img = ImageView:create(getResPath() .. imgBg)
	img:setScale9Enabled(true)
	img:setContentSize(CCSizeMake(self.sx, self.sy))
	img:setPosition(ccp(l:getContentSize().width / 2.0, l:getContentSize().height / 2.0))
	l:addChild(img)
	if data then
		l:addChild(data:getCOObj())
	end
	self._root:addPage(l)
end

function getClass()
	return clsPageView
end
